<style>
    .layui-form-label {
        width: 100px;
    }

    .layui-input-block {
        margin-left: 130px;
    }

    .import {
        opacity: 0;
        position: absolute;
        width: 69px;
        height: 38px;
        margin-left: -10px;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">类别名称：</label>
                                    <div class="layui-input-inline">
                                        <input name="name" class="layui-input" type="text" placeholder="请输入类别名称"
                                               autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                            lay-submit layui-form-keyDownSearch="true">查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置
                                    </button>
                                </div>
                            </div>
                            <div class="query-rt"></div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="productTypeBtnAdd" class="layui-btn icon-btn color-reseda">添加</button>
                            <button id="productTypeBtnImport" class="layui-btn icon-btn color-reseda">
                                <input id="uploaderInput" type="file" name="file" class="import" accept=".xls,.xlsx"/>导入
                            </button>
                        </div>
                        <div class="lay-btn-rt">
                            <button id="productTypeBtnTemplate" class="layui-btn icon-btn color-green">模板下载</button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="productTypeTable" lay-filter="productTypeTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="productTypeTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>

    {{# if(d.systemDefault==false){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    {{# } }}

    {{# if(d.finalClassifyStatus == 1){ }}
    <a class="layui-btn layui-btn-xs" lay-event="addSubProductType">添加子级</a>
    {{# } }}
</script>

<script type="text/html" id="productUnitPackBar">
    <a class="layui-btn layui-btn-xs" lay-event="productUnit">计量单位管理</a>
    <!--    <a class="layui-btn layui-btn-xs" lay-event="productPack">包装方案管理</a>-->
</script>

<script type="text/html" id="productSpecBar">
    <a class="layui-btn layui-btn-xs" lay-event="addSpec">添加规格</a>
    <a class="layui-btn layui-btn-xs" lay-event="specTable">规格列表</a>
</script>

<script type="text/html" id="productAttrBar">
    <a class="layui-btn  layui-btn-xs" lay-event="addAttr">添加属性</a>
    <a class="layui-btn  layui-btn-xs" lay-event="attrTable">属性列表</a>
</script>

<script type="text/html" id="productProcessBar">
    {{# if(d.type == '2'){ }}
    <a class="layui-btn  layui-btn-xs" lay-event="process">工序设置</a>
    {{# } }}
    <a class="layui-btn  layui-btn-xs" lay-event="itemTable">检测项管理</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="productTypeForm">
    <form lay-filter="productTypeForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">类别性质</label>
                <div class="layui-input-block">
                    <select id="materialNature" name="materialNature" lay-filter="materialNature">
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">上级类别</label>
                <input name="parentId" type="hidden"/>
                <div class="layui-input-block" id="selectParentType">
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">类别编码</label>
                <div class="layui-input-block">
                    <input name="code" placeholder="请输入类别编码" type="text" class="layui-input"
                           lay-verify="required|isOnlyName" required autocomplete="off"/>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">类别名称</label>
                <div class="layui-input-block">
                    <input name="name" placeholder="请输入类别名称" type="text" class="layui-input"
                           lay-verify="required|isOnlyName" required autocomplete="off"/>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">是否终极分类</label>
                <div class="layui-input-block">
                    <input type="radio" name="finalClassifyStatus" value="1" title="否" checked>
                    <input type="radio" name="finalClassifyStatus" value="0" title="是">
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">是否一物一码</label>
                <div class="layui-input-block">
                    <input type="radio" name="thingCodeStatus" value="1" title="否" checked>
                    <input type="radio" name="thingCodeStatus" value="0" title="是">
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">是否有质保期</label>
                <div class="layui-input-block">
                    <input type="radio" name="guaranteeStatus" value="1" title="否" checked>
                    <input type="radio" name="guaranteeStatus" value="0" title="是">
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">是否先进先出</label>
                <div class="layui-input-block">
                    <input type="radio" name="inoutStatus" value="1" title="否" checked>
                    <input type="radio" name="inoutStatus" value="0" title="是">
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item" id="depreciationTimeDiv" style="display: none">
                <label class="layui-form-label">折旧时长(月)</label>
                <div class="layui-input-block">
                    <input name="depreciationTime" placeholder="请输入折旧时长" type="text" class="layui-input"/>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">类别维护部门</label>
                <input name="typeServiceDepartment" type="hidden"/>
                <div class="layui-input-block" id="selectDepartment">
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-block">
                    <input name="isDeleted" type="checkbox" lay-skin="switch" value="1" checked="false"
                           lay-text="启用|停用"/>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-block">
                    <input name="sortNumber" placeholder="请输入排序" type="text" class="layui-input" lay-verify=""
                           required
                           autocomplete="off"/>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12">
            <div class="layui-form-item">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-block">
                    <textarea id="remark" name="remark" placeholder="请输入描述" class="layui-textarea"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="productTypeFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<script type="text/html" id="productSpecForm">
    <form lay-filter="productSpecForm" class="layui-form model-form form-scroll">
        <div class="open-details-box pd-20">
            <input name="id" type="hidden"/>
            <div class="layui-form-item" style="padding-top: 20px !important;">
                <label class="layui-form-label">物料类别</label>
                <div class="layui-input-block">
                    <select name="productTypeId" lay-filter="productTypeId" lay-search lay-verify="required" disabled>

                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">规格名称</label>
                <div class="layui-input-block">
                    <input name="specName" placeholder="请输入规格名称" type="text" class="layui-input"
                           lay-verify="required" required/>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">规格头</label>
                <div class="layui-input-block">
                    <input name="specHead" type="text" class="layui-input" lay-verify="required" required/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">引入规格码</label>
                <div class="layui-input-block">
                    <select name="specCode" lay-filter="style">
                        <option value="is">引入规格码</option>
                        <option value="no">不引入规格码中</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">规格补位位置</label>
                <div class="layui-input-block">
                    <select name="specLocation" lay-filter="style">
                        <option value="before">前置</option>
                        <option value="last">后置</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">规格参数排序</label>
                <div class="layui-input-block">
                    <input name="specSort" type="text" class="layui-input" lay-verify="required" required/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-block">
                    <textarea name="remark" placeholder="请输入描述" class="layui-textarea"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-block">
                    <input name="sortNumber" placeholder="请输入排序" type="text" class="layui-input" lay-verify=""
                           required/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">规格属性</label>
                <div class="layui-input-block">
                    <select name="style" lay-filter="style" lay-verify="required" required>
                        <option value="">请选择规格属性</option>
                        <option value="text">文本</option>
                        <option value="single">固定选择项</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item" id="btnAddDiv">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <button id="btnAdd" class="layui-btn" lay-filter="btnAdd" onclick="return false;">添加规格值
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right pd-20">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="productSpecFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<script type="text/html" id="productSpecTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="editSpec">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="productAttrTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="editAttr">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="productItemTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="editItem">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="specTable">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">名称：</label>
                            <div class="layui-input-inline mr0">
                                <input name="name" class="layui-input" type="text" placeholder="请输入名称"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-filter="specTableFormSubSearchLog" lay-submit
                                    layui-form-keyDownSearch="true"><i class="layui-icon">&#xe615;</i>搜索
                            </button>
                            <button id="productSpecBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加
                            </button>
                            <button id="productSpecBtnDel" class="layui-btn icon-btn layui-btn-danger"><i
                                    class="layui-icon"></i>批量删除
                            </button>
                        </div>
                    </div>
                </div>
                <!-- 表格 -->
                <table class="layui-table" id="productSpecTable" lay-filter="productSpecTable"></table>
            </div>
        </div>
    </div>
</script>

<script type="text/html" id="productAttrForm">
    <form lay-filter="productAttrForm" class="layui-form model-form" style="padding-top: 20px;">
        <input name="id" type="hidden"/>

        <div class="layui-form-item">
            <label class="layui-form-label">物料类别</label>
            <div class="layui-input-block">
                <select name="productTypeId" lay-filter="productTypeId" lay-search lay-verify="required" disabled>

                </select>
            </div>
        </div>

        <!--<div class="layui-form-item">
            <label class="layui-form-label">属性分类</label>
            <input name="categoryId" type="hidden"/>
            <div class="layui-input-block" id="selectCategory">
            </div>
        </div>-->

        <div class="layui-form-item">
            <label class="layui-form-label">属性名称</label>
            <div class="layui-input-block">
                <input name="attrName" placeholder="请输入名称" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>


        <!--<div class="layui-form-item">
            <label class="layui-form-label">属性头</label>
            <div class="layui-input-block">
                <input name="attrHeader" placeholder="请输入属性头" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>-->

        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="请输入描述" class="layui-textarea"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input name="isDeleted" type="checkbox" lay-skin="switch" value="1" checked="false"
                       lay-text="启用|停用"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input name="sortNumber" placeholder="请输入排序" type="text" class="layui-input" lay-verify=""
                       required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">属性类别</label>
            <div class="layui-input-block">
                <select name="style" lay-filter="style" lay-verify="required" required>
                    <option value="">请选择</option>
                    <option value="text">文本</option>
                    <option value="single">固定选择项</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item" id="btnAddDiv2">
            <label class="layui-form-label"></label>
            <div class="layui-input-inline">
                <button id="btnAdd2" class="layui-btn" lay-filter="btnAdd2" onclick="return false;">添加选择项</button>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="productAttrFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>


<script type="text/html" id="productAttributeCategoryForm">
    <form lay-filter="productAttributeCategoryForm" class="layui-form model-form">
        <input name="id" type="hidden"/>

        <div class="layui-form-item">
            <label class="layui-form-label">物料类别</label>
            <div class="layui-input-block">
                <select name="productTypeId" lay-filter="productTypeId" lay-search lay-verify="required" disabled>

                </select>
            </div>
        </div>

        <div class="layui-form-item" id="PID">
            <label class="layui-form-label">所属分类</label>
            <input name="parentId" type="hidden"/>
            <div class="layui-input-block" id="selectCategory4AttrCategory">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input name="name" placeholder="请输入名称" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea id="remark" name="remark" placeholder="请输入描述" class="layui-textarea"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否终极分类</label>
            <div class="layui-input-block">
                <input name="isFinal" type="checkbox" lay-skin="switch" value="1" lay-text="终极分类|非终极分类"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input name="isDeleted" type="checkbox" lay-skin="switch" value="1" checked="false"
                       lay-text="启用|停用"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input name="sortNumber" placeholder="请输入排序" type="text" class="layui-input" lay-verify=""
                       required/>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="productAttributeCategoryFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>


<script type="text/html" id="attrTable">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">名称：</label>
                            <div class="layui-input-inline mr0">
                                <input name="name" class="layui-input" type="text" placeholder="请输入名称"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-filter="attrTableFormSubSearchLog" lay-submit
                                    layui-form-keyDownSearch="true"><i class="layui-icon">&#xe615;</i>搜索
                            </button>
                            <button id="productAttrBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加
                            </button>
                            <button id="productAttrCategoryBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加分类
                            </button>
                            <button id="productAttrBtnDel" class="layui-btn icon-btn layui-btn-danger"><i
                                    class="layui-icon"></i>批量删除
                            </button>
                        </div>
                    </div>
                </div>
                <!-- 表格 -->
                <table class="layui-table" id="productAttrTable" lay-filter="productAttrTable"></table>
            </div>
        </div>
    </div>
</script>
<!-- 检测项目 -->
<script type="text/html" id="itemTable">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">名称：</label>
                            <div class="layui-input-inline mr0">
                                <input name="name" class="layui-input" type="text" placeholder="请输入名称"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-filter="itemTableFormSubSearchLog" lay-submit
                                    layui-form-keyDownSearch="true"><i class="layui-icon">&#xe615;</i>搜索
                            </button>
                            <button id="productItemBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加检测项目
                            </button>
                            <button id="productItemCategoryBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>检测项目分类
                            </button>
                        </div>
                    </div>
                </div>
                <!-- 表格 -->
                <table class="layui-table" id="productItemTable" lay-filter="productItemTable"></table>
            </div>
        </div>
    </div>
</script>
<script type="text/html" id="productItemForm">
    <form lay-filter="productItemForm" class="layui-form model-form" style="padding-top: 20px;">
        <input name="id" type="hidden"/>

        <div class="layui-form-item">
            <label class="layui-form-label">物资分类</label>
            <div class="layui-input-block">
                <select id="productType" name="productType" lay-filter="productType" disabled></select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">物资性质</label>
            <div class="layui-input-block">
                <select id="productNature" name="productNature" lay-filter="productNature" disabled></select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">检测类型</label>
            <div class="layui-input-block">
                <select id="itemType" name="itemType" lay-filter="itemType"></select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">检测项目分类</label>
            <div class="layui-input-block">
                <select id="itemCategoryId" name="itemCategoryId" lay-filter="itemCategoryId"></select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">检测项目代码</label>
            <div class="layui-input-block">
                <input name="code" placeholder="请输入检测项目代码" type="text" class="layui-input"
                       lay-verify="required"
                       required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">检测项目名称</label>
            <div class="layui-input-block">
                <input name="name" placeholder="请输入检测项目名称" type="text" class="layui-input"
                       lay-verify="required"
                       required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">样式</label>
            <div class="layui-input-block">
                <select id="style" name="style" lay-filter="style"></select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="请输入描述" class="layui-textarea"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input name="sort" placeholder="请输入排序" type="text" class="layui-input" lay-verify=""
                       required/>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="productItemFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>
<script type="text/html" id="productItemCategoryForm">
    <form lay-filter="productItemCategoryForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">物资分类</label>
            <input name="productType" type="hidden"/>
            <div class="layui-input-inline mr0" id="selectProductTypeQuery" style="width: 277px;" disabled></div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">物资性质</label>
            <div class="layui-input-block">
                <select id="productNature" name="productNature" disabled></select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">检测类型</label>
            <div class="layui-input-block">
                <select id="itemType" name="itemType" lay-search lay-verify="required"></select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">编码</label>
            <div class="layui-input-block">
                <input name="code" placeholder="请输入编码" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input name="name" placeholder="请输入名称" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input name="sort" placeholder="请输入排序" type="text" class="layui-input" lay-verify="number"
                       required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea id="remark" name="remark" placeholder="请输入备注" class="layui-textarea"/>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="productItemCategoryFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>
<script type="text/html" id="productUnitTab">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">名称：</label>
                            <div class="layui-input-inline mr0">
                                <input name="name" class="layui-input" type="text" placeholder="请输入名称"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-filter="productUnitTabFormSubSearchLog" lay-submit
                                    layui-form-keyDownSearch="true"><i class="layui-icon">&#xe615;</i>搜索
                            </button>
                            <button id="productUnitBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加
                            </button>
                            <button id="productUnitBtnDel" class="layui-btn icon-btn layui-btn-danger"><i
                                    class="layui-icon"></i>批量删除
                            </button>
                        </div>
                    </div>
                </div>
                <!-- 表格 -->
                <table class="layui-table" id="productUnitTable" lay-filter="productUnitTable"></table>
            </div>
        </div>
    </div>

</script>


<script type="text/html" id="productUnitTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="productUnitForm">
    <form lay-filter="productUnitForm" class="layui-form model-form">
        <input name="id" type="hidden"/>

        <div class="layui-form-item">
            <label class="layui-form-label">物料类别</label>
            <div class="layui-input-block">
                <select name="productTypeId" lay-filter="productType" lay-verify="required" lay-search disabled>
                    <option value=""> 请选择物料类别</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input name="name" placeholder="请输入名称" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">是否基础单位</label>
            <div class="layui-input-block">
                <input name="isBaseUnit" type="checkbox" lay-skin="switch" value="1" lay-text="是|否"
                       lay-filter="isBaseUnit"/>
            </div>
        </div>
        <!--<div class="layui-form-item" id="baseRateDiv">
            <label class="layui-form-label">换算率</label>
            <div class="layui-input-block">
                <input name="baseRate" placeholder="请输入换算率" type="text" class="layui-input" lay-verify="" required/>
            </div>
        </div>-->

        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="请输入描述" class="layui-textarea"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input name="isDeleted" type="checkbox" lay-skin="switch" value="1" checked="false"
                       lay-text="启用|停用"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input name="sortNumber" placeholder="请输入排序" type="text" class="layui-input" lay-verify=""
                       required/>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="productUnitFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<script type="text/html" id="productPackTab">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">计量编号：</label>
                            <div class="layui-input-inline mr0">
                                <input name="code" class="layui-input" type="text" placeholder="请输入计量编号"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">名称：</label>
                            <div class="layui-input-inline mr0">
                                <input name="name" class="layui-input" type="text" placeholder="请输入名称"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-filter="productPackTabFormSubSearchLog" lay-submit
                                    layui-form-keyDownSearch="true"><i class="layui-icon">&#xe615;</i>搜索
                            </button>
                            <button id="productPackBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加
                            </button>
                            <button id="productPackBtnDel" class="layui-btn icon-btn layui-btn-danger"><i
                                    class="layui-icon"></i>批量删除
                            </button>
                        </div>
                    </div>
                </div>
                <!-- 表格 -->
                <table class="layui-table" id="productPackTable" lay-filter="productPackTable"></table>
            </div>
        </div>
    </div>
</script>


<!-- 表格操作列 -->
<script type="text/html" id="productPackTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="productPackForm">
    <form lay-filter="productPackForm" class="layui-form model-form">
        <input name="id" type="hidden"/>

        <div class="layui-form-item">
            <label class="layui-form-label">物料类别</label>
            <div class="layui-input-block">
                <select name="productTypeId" lay-filter="productType" lay-verify="required" lay-search disabled>
                    <option value=""> 请选择物料类别</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">包裝计量名称</label>
            <div class="layui-input-block">
                <input name="name" placeholder="请输入包装计量名称" type="text" class="layui-input"
                       lay-verify="required" required/>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">物料单位</label>
            <div class="layui-input-block">
                <select id="productUnitId" name="productUnitId" lay-filter="productUnitId" lay-verify="required"
                        lay-search>
                    <option value=""> 请选择物料单位</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">换算方式</label>
            <div class="layui-input-block">
                <select name="rateType">
                    <option value="fixed">固定换算率</option>
                    <option value="floating">浮动</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">换算率</label>
            <div class="layui-input-block">
                <input name="baseRate" placeholder="请输入换算率" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="请输入描述" class="layui-textarea"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input name="isDeleted" type="checkbox" lay-skin="switch" value="1" checked="false"
                       lay-text="启用|停用"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input name="sortNumber" placeholder="请输入排序" type="text" class="layui-input" lay-verify=""
                       required/>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="productPackFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<script id="processInfoWindow" type="text/html">
    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <button id="processInfoBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加
                            </button>
                            <button id="processInfoBtnExport" class="layui-btn icon-btn"><i
                                    class="layui-icon">&#xe67d;</i>导出
                            </button>

                        </div>
                    </div>
                </div>
                <!-- 表格 -->
                <table class="layui-table" id="processInfoTable" lay-filter="processInfoTable"></table>
            </div>
        </div>
    </div>
</script>

<script id="processInfoAddWindow" type="text/html">

    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 表格 -->
                <table class="layui-table" id="processInfoAddTable" lay-filter="processInfoAddTable"></table>
            </div>
            <div class="layui-form-item text-right">
                <button class="layui-btn" lay-filter="processInfoAddSubmit" lay-submit>保存</button>
            </div>
        </div>
    </div>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'laydate', 'admin', 'laytpl', 'tableTreeDj', 'config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var laydate = layui.laydate;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laytpl = layui.laytpl;
        var tableTree = layui.tableTreeDj;

        // 渲染表格
        var insTb = tableTree.render({
            id: 'productTypeTable',
            elem: '#productTypeTable',
            url: config.base + 'enterprise/product/admin/productType/list?enterprise=0',
            toolbar: true,
            defaultToolbar: ["filter"],
            where: {limit: 99999},
            page: false,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号', fixed: 'left'}
                , {field: 'name', align: 'left', title: '类别名称', width: 200}
                , {field: 'code', align: 'center', title: '类别编号', width: 145}
                , {field: 'materialNatureName', align: 'center', title: '物资性质', width: 145}
                , {field: 'typeServiceDepartmentName', align: 'center', title: '类别维护部门', width: 175}
                , {
                    field: 'isDeleted', align: 'center', title: '是否启用', templet: function (d) {
                        if (d.isDeleted) {
                            return '<input name="isDeleted" type="checkbox" lay-skin="switch" value="' + d.id + '" checked="' + d.isDeleted + '" lay-filter="isDeleted"  lay-text="启用|停用"/>';
                        } else {
                            return '<input name="isDeleted" type="checkbox" lay-skin="switch" value="' + d.id + '" lay-filter="isDeleted"   lay-text="启用|停用"/>';
                        }
                    }
                },
                {
                    field: 'systemDefault', align: 'center', title: '是否系统默认类别', templet: function (d) {
                        if (d.systemDefault) {
                            return '是';
                        } else {
                            return '否';
                        }
                    }, width: 180
                }
                ,
                {align: 'center', toolbar: '#productUnitPackBar', title: '计量单位管理', width: 220}

                , {align: 'center', toolbar: '#productSpecBar', title: '规格管理', width: 180}
                , {align: 'center', toolbar: '#productAttrBar', title: '属性管理', width: 180}
                , {align: 'center', toolbar: '#productProcessBar', title: '检测项管理', width: 200}
                , {field: 'createTime', align: 'center', title: '创建时间', width: 180}
                , {align: 'center', toolbar: '#productTypeTableBar', title: '操作', width: 220, fixed: 'right'}
            ]],
            done: function (res, curr, count) {
                //移除按钮
                var menuButton = config.getMenuButton(location.hash);
                if (menuButton.indexOf("搜索") == -1) {
                    $('.layui-form.toolbar').remove();
                }
                if (menuButton.indexOf("修改") == -1) {
                    $("[lay-event='edit']").remove();
                }
                if (menuButton.indexOf("删除") == -1) {
                    $("[lay-event='del']").remove();
                }
            }
        }, {keyPid: "parentId", title: "name"});

        // 工具条点击事件
        table.on('tool(productTypeTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                admin.req('enterprise/product/admin/productType/get', {id: data.id}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        data = res.data;
                        data.eventType = 'edit';
                        showEditModel(data);
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'GET');
            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            } else if (obj.event == 'addSpec') {
                data.eventType = 'addSpec'
                showEditSpecModel(data);
            } else if (obj.event == 'specTable') {
                showSpecTableModel(data);
            } else if (obj.event == 'addAttr') {
                data.eventType = 'addAttr'
                showEditAttrModel(data);
            } else if (obj.event == 'attrTable') {
                showAttrTableModel(data);
            } else if (obj.event == 'itemTable') {
                showItemTableModel(data);
            } else if (obj.event == 'productUnit') {
                showEditUnitModel(data);
            } else if (obj.event == 'productPack') {
                showEditPackModel(data);
            } else if (obj.event == 'process') {
                showProcessModel(data);
            } else if (obj.event === 'addSubProductType') {
                var addSubProductTypeData = {};
                addSubProductTypeData.eventType = 'addSubProductType';
                addSubProductTypeData.materialNature = data.materialNature;
                addSubProductTypeData.parentId = data.id;
                addSubProductTypeData.typeServiceDepartment = data.typeServiceDepartment;
                admin.req('enterprise/product/admin/productType/getCount', {id: data.id}, function (res) {
                    if (res.code === 200) {
                        addSubProductTypeData.code = data.code + "-" + (res.data + 1);
                        showEditModel(addSubProductTypeData);
                    }
                }, 'GET');
            }
        });

        form.on('switch(isDeleted)', function (obj) {
            if (obj.elem.checked) {
                enable(obj.value)
            } else {
                disable(obj.value)
            }
        })

        function enable(id) {
            admin.req('enterprise/product/admin/productType/enable', {id: id}, function (res) {
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1});
                    table.reload('productTypeTable');
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'POST');
        }

        function disable(id) {
            admin.req('enterprise/product/admin/productType/disable', {id: id}, function (res) {
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1});
                    table.reload('productTypeTable');
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'POST');
        }

        //监听排序
        table.on('sort(productTypeTable)', function (obj) {
            table.reload('productTypeTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', data => {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        // 添加按钮点击事件
        $('#productTypeBtnAdd').click(function () {
            var addData = {};
            addData.eventType = 'add';
            showEditModel(addData);
        });

        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: '840px',
                offset: ['150px', '520px'],
                title: data.eventType == 'edit' ? '修改物料类别' : '添加物料类别',
                content: $('#productTypeForm').html(),
                success: function () {
                    //类别性质
                    admin.getDictList("materialNature", "sys_product_type_nature", data.materialNature, "类别性质");
                    //类别维护部门
                    admin.initDataSelectTree(true, "user/admin/role/getTreeData", null, 'selectDepartment', data.typeServiceDepartment, '类别维护部门', 'typeServiceDepartment', null);

                    form.val('productTypeForm', data);

                    if (data) {
                        var hasBoxOption = $("form select[name='hasUseBox']").find("option");
                        layui.each(hasBoxOption, function (index, item) {
                            if (data.hasUseBox) {
                                data.hasUseBox = 1;
                            } else {
                                data.hasUseBox = 0;
                            }
                        });
                    }

                    form.verify({
                        isOnlyName: function (value) {
                            var isOnly = true;
                            var idVal = $("form input[name='id']").val();
                            admin.req('enterprise/product/admin/productType/isOnly', {
                                name: value,
                                id: idVal
                            }, function (res) {
                                if (res.code == 200) {
                                    isOnly = res.data;
                                }
                            }, 'GET', false);
                            if (!isOnly) {
                                return "名称必须唯一"
                            }
                        }
                    })

                    if (data && data.materialNature == 3) {
                        $('#depreciationTimeDiv').show();
                    }

                    form.val('productTypeForm', data);
                    form.render();

                    //初始化
                    admin.initDataSelectTree(true, 'enterprise/product/admin/productType/getTreeData', {productTypeId: data == undefined ? null : data.id}, 'selectParentType', data.parentId, "上级类别", "parentId", function (data) {
                        // 获取上级类别ID
                        var parentTypeId = data.change[0].value;
                        admin.req('enterprise/product/admin/productType/get', {id: parentTypeId}, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                //类别维护部门
                                admin.initDataSelectTree(true, "user/admin/role/getTreeData", null, 'selectDepartment', res.data.typeServiceDepartment, '类别维护部门', 'typeServiceDepartment', null);
                                admin.req('enterprise/product/admin/productType/getCount', {productTypeId: parentTypeId}, function (response) {
                                    if (response.code == 200) {
                                        $('input[name="code"]').val(res.data.code + "-" + (response.data + 1));
                                    }
                                }, 'GET');
                            }
                        }, 'GET');
                    });

                    form.on('select(materialNature)', function (data) {
                        if (data.value == 3) {
                            $('#depreciationTimeDiv').show();
                        } else {
                            $('#depreciationTimeDiv').hide();
                        }
                    })

                    // 表单提交事件
                    form.on('submit(productTypeFormSubmit)', function (d) {
                        layer.load(2);

                        var isDeleted = $("form input[name='isDeleted']").prop("checked");
                        if (!isDeleted) {
                            d.field.isDeleted = false;
                        } else {
                            d.field.isDeleted = true;
                        }
                        admin.req(data.eventType == 'edit' ? 'enterprise/product/admin/productType/update' : 'enterprise/product/admin/productType/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productTypeTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data.eventType == 'edit' ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
        }

        function showEditUnitModel(productTypeData) {
            admin.open({
                type: 1,
                area: '1440px',
                offset: '65px',
                title: '计量单位管理',
                content: $('#productUnitTab').html(),
                success: function () {
                    // 渲染表格
                    var insTb = table.render({
                        elem: '#productUnitTable',
                        url: config.base + 'enterprise/product/admin/productUnit/list?productType=' + productTypeData.id,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            , {field: 'name', align: 'center', title: '单位名称'}
                            , {field: 'code', align: 'center', title: '单位编码'}
                            , {field: 'productTypeName', title: '物料类别'}
                            , {
                                field: 'isBaseUnit', align: 'center', title: '是否基础单位', templet: function (d) {
                                    if (d.isBaseUnit) {
                                        return '是'
                                    } else {
                                        return '否'
                                    }
                                }
                            }


                            , {field: 'baseRate', align: 'center', title: '换算率'}
                            , {field: 'remark', align: 'center', title: '描述'}
                            , {field: 'createTime', align: 'center', title: '创建时间'}
                            , {
                                field: 'isDeleted', align: 'center', title: '是否启用', templet: function (d) {
                                    if (d.isDeleted) {
                                        return '<input name="isDeleted" type="checkbox" lay-skin="switch" value="' + d.id + '" checked="' + d.isDeleted + '" lay-filter="isDeleted"  lay-text="启用|停用"/>';
                                    } else {
                                        return '<input name="isDeleted" type="checkbox" lay-skin="switch" value="' + d.id + '" lay-filter="isDeleted"   lay-text="启用|停用"/>';
                                    }

                                }
                            }
                            // ,{align: 'center', toolbar: '#productUnitTableBar', title: '操作', width: 200}
                        ]],
                        done: function (res, curr, count) {
                            //移除按钮
                            var menuButton = config.getMenuButton(location.hash);
                            if (menuButton.indexOf("搜索") == -1) {
                                $('.layui-form.toolbar').remove();
                            }
                            if (menuButton.indexOf("修改") == -1) {
                                $("[lay-event='edit']").remove();
                            }
                            if (menuButton.indexOf("删除") == -1) {
                                $("[lay-event='del']").remove();
                            }
                        }
                    });

                    // 工具条点击事件
                    table.on('tool(productUnitTable)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'edit') { //修改
                            showEditModel(data);
                        } else if (obj.event === 'del') { // 删除
                            doDelete(obj);
                        }
                    });

                    //监听排序
                    table.on('sort(productUnitTable)', function (obj) {
                        table.reload('productUnitTable', {
                            initSort: obj
                            , where: {
                                sort: obj.field
                                , order: obj.type
                            }
                        });
                    });

                    // 搜索
                    form.on('submit(productUnitTabFormSubSearchLog)', function (data) {
                        insTb.reload({where: data.field, page: {curr: 1}}, 'data');
                    });

                    form.on('switch(isDeleted)', function (obj) {
                        if (obj.elem.checked) {
                            enable(obj.value)
                        } else {
                            disable(obj.value)
                        }
                    })

                    function enable(id) {
                        admin.req('enterprise/product/admin/productUnit/enable', {id: id}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productUnitTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST');
                    }

                    function disable(id) {
                        admin.req('enterprise/product/admin/productUnit/disable', {id: id}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productUnitTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST');
                    }

                    function isShowAdd() {
                        admin.req('enterprise/product/admin/productUnit/countByProductType', {productType: productTypeData.id}, function (res) {
                            if (res.code == 200) {
                                if (parseInt(res.data) > 0) {
                                    $("#productUnitBtnAdd").hide();
                                } else {
                                    $("#productUnitBtnAdd").show();
                                }
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                    }

                    // isShowAdd();

                    // 添加按钮点击事件
                    $('#productUnitBtnAdd').click(function () {
                        showEditModel();
                    });

                    $('#productUnitBtnDel').click(function () {
                        var checkRows = table.checkStatus('productUnitTable');
                        if (checkRows.data.length == 0) {
                            layer.msg('请选择要删除的数据', {icon: 2});
                        } else {
                            var ids = '';
                            checkRows.data.forEach(item => {
                                ids += item.id + ','
                            })
                            delBatch(ids)
                        }
                    });

                    function delBatch(ids) {
                        admin.req('enterprise/product/admin/productUnit/delBatch', {ids: ids}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productUnitTable');
                                // isShowAdd();
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST');
                    }

                    // 显示编辑弹窗
                    function showEditModel(data) {
                        var windowIndex = admin.open({
                            type: 1,
                            area: '680px',
                            offset: '65px',
                            title: data ? '修改物料单位' : '添加物料单位',
                            content: $('#productUnitForm').html(),
                            success: function () {
                                if (data == undefined || (data && data.isBaseUnit)) {
                                    $("from input[name='baseRate']").removeAttr('lay-verify', 'required')
                                    $("#baseRateDiv").hide();
                                } else if (data && !data.isBaseUnit) {
                                    $("from input[name='baseRate']").attr('lay-verify', 'required')
                                    $("#baseRateDiv").show();
                                }
                                form.render();

                                form.on('switch(isBaseUnit)', function (data) {
                                    if (data.elem.checked) {
                                        $("from input[name='baseRate']").removeAttr('lay-verify', 'required')
                                        $("#baseRateDiv").hide();
                                    } else {
                                        $("from input[name='baseRate']").attr('lay-verify', 'required')
                                        $("#baseRateDiv").show();
                                    }
                                })

                                /**
                                 admin.req('enterprise/product/admin/productType/list', {limit:9999}, function (res) {
                                    if ( res.code==200) {
                                        var html='<option value=""> 请选择物料类别</option>';
                                        for(var k=0;k<res.data.length;k++){
                                            html+='<option value="'+res.data[k].id+'">'+res.data[k].name+'</option>';
                                        }
                                        $("form select[name='productType']").html(html);
                                        form.render('select')
                                        if(data){
                                            $("form select[name='productType']").val(data.productType);
                                        }
                                    } else {
                                        layer.msg('获取物料类别失败', {icon: 2, time: 1000});
                                    }
                                }, 'GET');*/
                                var option = '<option selected>' + productTypeData.name + '</option>'
                                $("form select[name='productTypeId']").html(option);
                                form.render('select')

                                form.val('productUnitForm', data);
                                // 表单提交事件
                                form.on('submit(productUnitFormSubmit)', function (d) {
                                    layer.load(2);

                                    var isDeleted = $("form input[name='isDeleted']").prop("checked");
                                    if (!isDeleted) {
                                        d.field.isDeleted = false;
                                    } else {
                                        d.field.isDeleted = true;
                                    }

                                    var isBaseUnit = $("form input[name='isBaseUnit']").prop("checked");
                                    if (!isBaseUnit) {
                                        d.field.isBaseUnit = false;
                                    } else {
                                        d.field.isBaseUnit = true;
                                    }
                                    d.field.productType = productTypeData.id;
                                    admin.req(data ? 'enterprise/product/admin/productUnit/update' : 'enterprise/product/admin/productUnit/add', d.field, function (res) {
                                        layer.closeAll('loading');
                                        if (res.code == 200) {
                                            layer.msg(res.msg, {icon: 1});
                                            table.reload('productUnitTable');
                                            // layer.closeAll('page');
                                            layer.close(windowIndex);
                                            // isShowAdd();
                                        } else {
                                            layer.msg(res.msg, {icon: 2});
                                        }
                                    }, data ? 'PUT' : 'POST');
                                    return false;
                                });
                            }
                        });
                    }

                    // 删除
                    function doDelete(obj) {
                        layer.confirm('确定要删除吗？', {
                            offset: '65px',
                            skin: 'layui-layer-admin'
                        }, function (i) {
                            layer.close(i);
                            layer.load(2);
                            admin.req('enterprise/product/admin/productUnit/' + obj.data.id, {}, function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    obj.del();
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'DELETE');
                        });
                    }
                }
            })
        }

        function showEditPackModel(productTypeData) {
            admin.open({
                type: 1,
                area: '1440px',
                offset: '65px',
                title: '包装计量方案',
                content: $('#productPackTab').html(),
                success: function () {
                    var insTb = table.render({
                        elem: '#productPackTable',
                        url: config.base + 'enterprise/product/admin/productPack/list?productType=' + productTypeData.id,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            , {field: 'name', align: 'center', title: '包装计量方案名称', width: 150,}
                            , {field: 'code', align: 'center', title: '包装计量方案编码', width: 150}
                            , {field: 'packUnitName', title: '包装单位'}
                            , {field: 'productTypeName', title: '所属物料类别'}
                            /*,{field: 'isBaseUnit', align: 'center', title: '是否基础单位',templet:function (d) {
                                    if(d.isBaseUnit){
                                        return '是'
                                    }else{
                                        return  '否'
                                    }
                                }}*/
                            , {field: 'baseRate', align: 'center', title: '换算率'}
                            , {
                                field: 'converteMethod', align: 'center', title: '换算公式', templet: function (d) {
                                    return `1${d.productUnitName}=${d.baseRate}${d.basicsUnitName}`
                                }
                            }

                            , {
                                field: 'isDeleted', align: 'center', title: '是否启用', templet: function (d) {
                                    if (d.isDeleted) {
                                        return '<input name="isDeleted" type="checkbox" lay-skin="switch" value="' + d.id + '" checked="' + d.isDeleted + '" lay-filter="isDeleted"  lay-text="启用|停用"/>';
                                    } else {
                                        return '<input name="isDeleted" type="checkbox" lay-skin="switch" value="' + d.id + '" lay-filter="isDeleted"   lay-text="启用|停用"/>';
                                    }

                                }
                            }
                            , {field: 'creatorName', align: 'center', title: '创建人'}
                            , {field: 'createTime', align: 'center', title: '创建时间'}
                            // ,{align: 'center', toolbar: '#productPackTableBar', title: '操作', width: 200}
                        ]],
                        done: function (res, curr, count) {
                            //移除按钮
                            var menuButton = config.getMenuButton(location.hash);
                            if (menuButton.indexOf("搜索") == -1) {
                                $('.layui-form.toolbar').remove();
                            }
                            if (menuButton.indexOf("修改") == -1) {
                                $("[lay-event='edit']").remove();
                            }
                            if (menuButton.indexOf("删除") == -1) {
                                $("[lay-event='del']").remove();
                            }
                        }
                    });

                    // 工具条点击事件
                    table.on('tool(productPackTable)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'edit') { //修改
                            showEditModel(data);
                        } else if (obj.event === 'del') { // 删除
                            doDelete(obj);
                        }
                    });

                    //监听排序
                    table.on('sort(productPackTable)', function (obj) {
                        table.reload('productPackTable', {
                            initSort: obj
                            , where: {
                                sort: obj.field
                                , order: obj.type
                            }
                        });
                    });

                    // 搜索
                    form.on('submit(productPackTabFormSubSearchLog)', function (data) {
                        insTb.reload({where: data.field, page: {curr: 1}}, 'data');
                    });

                    form.on('switch(isDeleted)', function (obj) {
                        if (obj.elem.checked) {
                            enable(obj.value)
                        } else {
                            disable(obj.value)
                        }
                    })

                    function enable(id) {
                        admin.req('enterprise/product/admin/productPack/enable', {id: id}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productPackTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST');
                    }

                    function disable(id) {
                        admin.req('enterprise/product/admin/productPack/disable', {id: id}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productPackTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST');
                    }

                    // 添加按钮点击事件
                    $('#productPackBtnAdd').click(function () {
                        showEditModel();
                    });

                    $('#productPackBtnDel').click(function () {
                        var checkRows = table.checkStatus('productPackTable');
                        if (checkRows.data.length == 0) {
                            layer.msg('请选择要删除的数据', {icon: 2});
                        } else {
                            var ids = '';
                            checkRows.data.forEach(item => {
                                ids += item.id + ','
                            })
                            delBatch(ids)
                        }
                    });

                    function delBatch(ids) {
                        admin.req('enterprise/product/admin/productPack/delBatch', {ids: ids}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productPackTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST');
                    }

                    // 显示编辑弹窗
                    function showEditModel(data) {
                        var windowIndex = admin.open({
                            type: 1,
                            area: '760px',
                            offset: '65px',
                            title: data ? '修改物料包装' : '添加物料包装',
                            content: $('#productPackForm').html(),
                            success: function () {
                                if (data) {
                                    var option = $("form select[name='rateType']").find("option");
                                    layui.each(option, function (index, item) {
                                        if (data.rateType == item.text) {
                                            data.rateType = item.value;
                                        }
                                    });
                                }
                                /**
                                 admin.req('enterprise/product/admin/productType/list', {limit:9999}, function (res) {
                                    if ( res.code==200) {
                                        var html='<option value=""> 请选择物料类别</option>';
                                        for(var k=0;k<res.data.length;k++){
                                            html+='<option value="'+res.data[k].id+'" data-productTypeCode="'+res.data[k].code+'">'+res.data[k].name+'</option>';
                                        }
                                        $("form select[name='productType']").html(html);
                                        form.render('select')
                                        if(data){
                                            $("form select[name='productType']").val(data.productType);
                                            getProductUnit(data.productType,false);
                                        }
                                    } else {
                                        layer.msg('获取物料类别失败', {icon: 2, time: 1000});
                                    }
                                }, 'GET');*/
                                var option = '<option selected>' + productTypeData.name + '</option>'
                                $("form select[name='productTypeId']").html(option);
                                form.render('select')


                                var getProductUnit = function (productType, reSelect) {
                                    admin.req('enterprise/product/admin/productUnit/list', {
                                        productType: productType,
                                        limit: 9999
                                    }, function (res) {
                                        if (res.code == 200) {
                                            var html = '<option value=""> 请选择物料单位</option>';
                                            for (var k = 0; k < res.data.length; k++) {
                                                if (!res.data[k].isBaseUnit) {
                                                    html += '<option value="' + res.data[k].id + '" data-productUnitCode="' + res.data[k].code + '">' + res.data[k].name + '</option>';
                                                }
                                            }
                                            $("form select[name='productUnitId']").html(html);
                                            form.render('select')
                                            if (data && !reSelect) {
                                                $("form select[name='productUnitId']").val(data.productUnitId);
                                                form.render()
                                            }
                                        } else {
                                            layer.msg('获取物料类别失败', {icon: 2, time: 1000});
                                        }
                                    }, 'GET');
                                }

                                getProductUnit(productTypeData.id, false);

                                form.on('select(productType)', function (data) {
                                    if (data.value != '') {
                                        getProductUnit(data.value, true);
                                    }
                                })

                                form.val('productPackForm', data);
                                // 表单提交事件
                                form.on('submit(productPackFormSubmit)', function (d) {
                                    layer.load(2);
                                    var isDeleted = $("form input[name='isDeleted']").prop("checked");
                                    if (!isDeleted) {
                                        d.field.isDeleted = false;
                                    } else {
                                        d.field.isDeleted = true;
                                    }
                                    // d.field.productTypeCode=$("form select[name='productType'] option:selected").data('producttypecode');
                                    d.field.productUnitCode = $("form select[name='productUnitId'] option:selected").data('productunitcode');
                                    d.field.productType = productTypeData.id;
                                    d.field.productTypeCode = productTypeData.code;
                                    admin.req(data ? 'enterprise/product/admin/productPack/update' : 'enterprise/product/admin/productPack/add', d.field, function (res) {
                                        layer.closeAll('loading');
                                        if (res.code == 200) {
                                            layer.msg(res.msg, {icon: 1});
                                            table.reload('productPackTable');
                                            // layer.closeAll('page');
                                            layer.close(windowIndex);
                                        } else {
                                            layer.msg(res.msg, {icon: 2});
                                        }
                                    }, data ? 'PUT' : 'POST');
                                    return false;
                                });
                            }
                        });
                    }

                    // 删除
                    function doDelete(obj) {
                        layer.confirm('确定要删除吗？', {
                            offset: '65px',
                            skin: 'layui-layer-admin'
                        }, function (i) {
                            layer.close(i);
                            layer.load(2);
                            admin.req('enterprise/product/admin/productPack/' + obj.data.id, {}, function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    obj.del();
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'DELETE');
                        });
                    }
                }
            })
        }

        function showEditSpecModel(data) {
            var openIndex = admin.open({
                type: 1,
                area: ['840px', '760px'],
                offset: '65px',
                title: data && (data.eventType == 'addSpec' || data.eventType == 'addSpecFromSpecTable') ? '添加物料规格值' : '修改物料规格值',
                content: $('#productSpecForm').html(),
                success: function () {
                    var productTypeName = '';
                    if (data && data.eventType == 'editSpec') {
                        productTypeName = data.productTypeName;
                        data.specName = data.name;
                    } else {
                        productTypeName = data.name;
                    }


                    var option = '<option selected>' + productTypeName + '</option>'
                    $("form select[name='productTypeId']").html(option);
                    form.render('select')
                    if (data && data.eventType == 'addSpec') {
                        data.sortNumber = '';
                    }

                    form.val('productSpecForm', data);
                    form.render();

                    var getTemplateHtml = function (i) {
                        var labelName = '';
                        var valLen = $("form input[name='quantity']").length;
                        if (valLen == 0) {
                            labelName = '规格值';
                        }
                        var templateHtml = '' +
                            '<div class="layui-form-item" >' +
                            '<div class="layui-form-item">' +
                            '<div >' +
                            '<label class="layui-form-label" >' + labelName + '</label>' +
                            '<div class="layui-input-inline">' +
                            '<input id="value' + i + '" name="value" placeholder="请输规格值" type="text" class="layui-input" lay-verify="required" required/>' +
                            '</div>' +
                            '</div>' +
                            '<div >' +
                            '<div class="layui-input-inline">' +
                            '<input id="sort' + i + '" name="sort" placeholder="排序值" type="text" class="layui-input" lay-verify="sortNumber" required/>' +
                            '</div>' +
                            '</div>';

                        templateHtml += '<div class="layui-input-inline">' +
                            '<button id="btnDel' + i + '" class="layui-btn delBtn" lay-filter="btnDel' + i + '" style="margin-left: 20px;">删除</button>' +
                            '</div>';
                        templateHtml += '</div>' +
                            '</div>';
                        return templateHtml;
                    }

                    var i = 0;
                    var btnCount = 0;
                    var addTemplateDiv = function () {
                        var html = getTemplateHtml(i++);
                        $("#btnAddDiv").prev().after(html);
                        form.render();
                        form.render('select');
                        $(".delBtn").off('click').on('click', function () {
                            var btn = $(this);
                            var btnId = btn[0].id;
                            var btnNo = btnId.substring("btnDel".length, btnId.length);
                            btn.parent().parent().parent().remove();
                        });
                    };
                    $('#btnAdd').click(addTemplateDiv);
                    if (data == undefined || (data && (data.eventType == 'addSpec' || data.eventType == 'addSpecFromSpecTable'))) {
                        // addTemplateDiv();
                        $("#btnAdd").hide();
                        $("#btnDel0").hide();
                    }
                    form.on('select(style)', function (data) {
                        if (data.value == 'text') {
                            $("#btnAdd").hide();
                            $(".attributeDiv").remove();
                        } else if (data.value == 'single') {
                            $("#btnAdd").show();
                            if ($("form input[name='value']").length == 0) {
                                addTemplateDiv();
                                $("#btnDel0").hide();
                            }
                        }
                    })
                    if (data && data.eventType == 'editSpec') {
                        if (data.style === 'text') {
                            $("#btnAdd").hide();
                        }
                        if (data.style === 'single') {
                            admin.req('enterprise/product/admin/productSpecValue/list', {
                                productSpecId: data.id,
                                limit: 9999
                            }, function (res) {
                                if (res.code == 200) {
                                    for (var k = 0; k < res.data.length; k++) {
                                        addTemplateDiv();
                                        $("#btnDel0").hide();
                                        var elementNo = i - 1;
                                        var value = res.data[k].value;
                                        var sortNumber = res.data[k].sortNumber;
                                        $("#value" + elementNo).val(value);
                                        $("#sort" + elementNo).val(sortNumber);
                                        form.render();
                                    }
                                } else {
                                    layer.msg('获取规格值失败', {icon: 2, time: 1000});
                                }
                            }, 'GET');
                        }
                    }

                    // 表单提交事件
                    form.on('submit(productSpecFormSubmit)', function (d) {
                        layer.load(2);
                        var detailList = [];
                        var vals = [];
                        var sorts = [];
                        $("form input[name='value']").each(function (index, item) {
                            var val = $(this).val();
                            vals.push(val);
                        });

                        $("form input[name='sort']").each(function (index, item) {
                            var val = $(this).val();
                            sorts.push(val);
                        });

                        for (var k = 0; k < vals.length; k++) {
                            var obj = {value: vals[k], sortNumber: sorts[k]};
                            detailList.push(obj)
                        }
                        if (data && (data.eventType == 'addSpec' || data.eventType == 'addSpecFromSpecTable')) {
                            d.field.id = undefined;
                            d.field.productType = data.id;
                        } else {
                            d.field.productType = data.productType;
                        }
                        d.field.name = d.field.specName;
                        d.field.detailList = detailList;
                        admin.req(data && (data.eventType == 'addSpec' || data.eventType == 'addSpecFromSpecTable') ? 'enterprise/product/admin/productSpec/add' : 'enterprise/product/admin/productSpec/update', JSON.stringify(d.field), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                if (data && (data.eventType == 'addSpecFromSpecTable' || data.eventType == 'editSpec')) {
                                    table.reload('productSpecTable');
                                    layer.close(openIndex);
                                } else {
                                    layer.closeAll('page');
                                }
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST', true, 'application/json; charset=utf-8');
                        return false;
                    });
                }
            });
        }

        //spec table
        function showSpecTableModel(data) {
            admin.open({
                type: 1,
                area: '1440px',
                offset: '65px',
                title: '物料规格管理',
                content: $('#specTable').html(),
                success: function () {
                    // 渲染表格
                    var insTb = table.render({
                        elem: '#productSpecTable',
                        url: config.base + 'enterprise/product/admin/productSpec/list?productType=' + data.id,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            , {type: 'numbers', title: '序号'}
                            , {field: 'name', align: 'center', title: '规格名称'}
                            , {field: 'productTypeName', align: 'center', title: '物料类别'}
                            , {field: 'specValues', align: 'center', title: '规格值'}
                            , {field: 'specHead', align: 'center', title: '规格头'}
                            , {field: 'specCodeDesc', align: 'center', title: '引入规格码'}
                            , {field: 'specLocationDesc', align: 'center', title: '规格补位位置'}
                            , {field: 'specSort', align: 'center', title: '规格参数排序'}
                            , {field: 'sortNumber', align: 'center', title: '排序'}
                            , {field: 'createTime', align: 'center', title: '创建时间'}
                            , {align: 'center', toolbar: '#productSpecTableBar', title: '操作', width: 200}
                        ]],
                        done: function (res, curr, count) {
                            //移除按钮
                            var menuButton = config.getMenuButton(location.hash);
                            if (menuButton.indexOf("搜索") == -1) {
                                $('.layui-form.toolbar').remove();
                            }
                            if (menuButton.indexOf("修改") == -1) {
                                $("[lay-event='edit']").remove();
                            }
                            if (menuButton.indexOf("删除") == -1) {
                                $("[lay-event='del']").remove();
                            }
                        }
                    });

                    // 工具条点击事件
                    table.on('tool(productSpecTable)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'editSpec') { //修改
                            data.eventType = 'editSpec'
                            showEditSpecModel(data);
                        } else if (obj.event === 'del') { // 删除
                            doDelete(obj);
                        }
                    });

                    function doDelete(obj) {
                        layer.confirm('确定要删除吗？', {
                            offset: '65px',
                            skin: 'layui-layer-admin'
                        }, function (i) {
                            layer.close(i);
                            layer.load(2);
                            admin.req('enterprise/product/admin/productSpec/' + obj.data.id, {}, function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    obj.del();
                                    table.reload('productSpecTable');
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'DELETE');
                        });
                    }

                    //监听排序
                    table.on('sort(productSpecTable)', function (obj) {
                        table.reload('productSpecTable', {
                            initSort: obj
                            , where: {
                                sort: obj.field
                                , order: obj.type
                            }
                        });
                    });

                    // 搜索
                    form.on('submit(specTableFormSubSearchLog)', function (data) {
                        insTb.reload({where: data.field, page: {curr: 1}}, 'data');
                    });

                    // 添加按钮点击事件
                    $('#productSpecBtnAdd').click(function () {
                        data.eventType = 'addSpecFromSpecTable'
                        showEditSpecModel(data);
                    });

                    $('#productSpecBtnDel').click(function () {
                        var checkRows = table.checkStatus('productSpecTable');
                        if (checkRows.data.length == 0) {
                            layer.msg('请选择要删除的数据', {icon: 2});
                        } else {
                            var ids = '';
                            checkRows.data.forEach(item => {
                                ids += item.id + ','
                            })
                            delBatch(ids)
                        }
                    });

                    function delBatch(ids) {
                        admin.req('enterprise/product/admin/productSpec/delBatch', {ids: ids}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productSpecTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST');
                    }
                }
            })
        }

        function showEditAttrCategoryModel(productTypeData, data, formId, submitButton, parentIdVal) {
            let finalCategoryIds = [];
            //加载终极分类
            admin.req('enterprise/product/admin/productAttributeCategory/list', {limit: 9999}, function (res) {
                if (res.code == 200) {
                    if (res.data != null) {
                        for (let i = 0; i < res.data.length; i++) {
                            if (res.data[i].isFinal == 'yes') {
                                finalCategoryIds.push(res.data[i].id)
                            }
                        }
                    }
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'get', false);
            var openIndex = admin.open({
                type: 1,
                area: '740px',
                offset: '65px',
                title: '添加属性分类',
                content: $('#productAttributeCategoryForm').html(),
                success: function () {

                    var productTypeName = productTypeData.name;


                    var option = '<option selected>' + productTypeName + '</option>'
                    $("form select[name='productTypeId']").html(option);
                    form.render('select')


                    var treeData = [];
                    admin.req('enterprise/product/admin/productAttributeCategory/getTreeData', {
                        limit: 9999,
                        productType: productTypeData.id
                    }, function (res) {
                        if (res.code == 200) {
                            treeData = res.data;
                        } else {
                            layer.msg('获取物料分类失败', {icon: 2, time: 1000});
                        }
                    }, 'GET', false);

                    var selectedData = function (treeData, targetId) {
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].value;
                            if (targetId == nodeId) {
                                treeData[k].selected = true;
                                return;
                            } else {
                                if (treeData[k].children && treeData[k].children != '') {
                                    selectedData(treeData[k].children, targetId);
                                }
                            }
                        }
                    }

                    if (data && data.eventType == 'editAttr') {
                        selectedData(treeData, data.categoryId);
                    }


                    xmSelect.render({
                        el: '#selectCategory4AttrCategory',
                        model: {label: {type: 'text'}},
                        radio: true,
                        clickClose: true,
                        filterable: true,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        height: 'auto',
                        data() {

                            return treeData;
                        },
                        on: function (data) {
                            //被选中的select的id,如果没有 -1
                            let parentId = data.arr.length > 0 ? data.change[0].value : -1;
                            $("input[name='parentId']").val(parentId);
                        },
                    });

                    var ele = $("#selectCategory4AttrCategory");
                    if (ele[0].children.length > 0) {
                        var eleChild = ele[0].children[0].children[0]
                        if (eleChild) {
                            // $(eleChild).attr('lay-verify','required');
                        }
                    }
                    form.render()


                    if (data) {
                        var option = $("form select[name='isFinal']").find("option");
                        layui.each(option, function (index, item) {
                            if (data.isFinal == item.text) {
                                data.isFinal = item.value;
                            }
                        });
                    }

                    form.val(formId, data);
                    // 表单提交事件
                    form.on('submit(' + submitButton + ')', function (d) {
                        layer.load(2);
                        if (d.field.parentId == null || d.field.parentId == '') {
                            d.field.parentId = -1
                        }
                        var isDeleted = $("form input[name='isDeleted']").prop("checked");
                        if (!isDeleted) {
                            d.field.isDeleted = false;
                        } else {
                            d.field.isDeleted = true;
                        }
                        var isFinal = $("form input[name='isFinal']").prop("checked");
                        if (!isFinal) {
                            d.field.isFinal = false;
                        } else {
                            d.field.isFinal = true;
                        }
                        d.field.productType = productTypeData.id;
                        admin.req(data ? 'enterprise/product/admin/productAttributeCategory/update' : 'enterprise/product/admin/productAttributeCategory/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                insTb.reload('productAttributeCategoryTable');
                                layer.close(openIndex)
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }

            })
        }

        //attr form
        function showEditAttrModel(data) {
            var openIndex = admin.open({
                type: 1,
                area: '740px',
                offset: '65px',
                title: data && (data.eventType == 'addAttr' || data.eventType == 'addAttrFromAttrTable') ? '添加物料属性' : '修改物料属性',
                content: $('#productAttrForm').html(),
                success: function () {
                    var productTypeName = '';
                    if (data && data.eventType == 'editAttr') {
                        productTypeName = data.productTypeName;
                        data.attrName = data.name;
                    } else {
                        productTypeName = data.name;
                    }
                    var option = '<option selected>' + productTypeName + '</option>'
                    $("form select[name='productTypeId']").html(option);
                    form.render('select')
                    if (data && data.eventType == 'addAttr') {
                        data.sortNumber = '';
                    }
                    form.val('productAttrForm', data);
                    form.render();

                    var getTemplateHtml = function (i) {
                        var labelName = '';
                        var valLen = $("form input[name='value']").length;
                        var classNew = '';
                        if (valLen == 0) {
                            labelName = '属性值';
                        } else {
                            classNew = 'newAdd'
                        }
                        var templateHtml = '' +
                            '<div class="attributeDiv layui-form-item ' + classNew + '" >' +
                            '<div class="layui-form-item">' +
                            '<div >' +
                            '<label class="layui-form-label" >' + labelName + '</label>' +
                            '<div class="layui-input-inline">' +
                            '<input id="value' + i + '" name="value" placeholder="请输入属性" type="text" class="layui-input" lay-verify="required" required/>' +
                            '</div>' +
                            '</div>' +
                            '<div >' +
                            '</div>';
                        templateHtml += '<div class="layui-input-inline">' +
                            '<button id="btnDel' + i + '" class="layui-btn delBtn" lay-filter="btnDel' + i + '" style="margin-left: 20px;">删除</button>' +
                            '</div>';
                        templateHtml += '</div>' + '</div>';
                        return templateHtml;
                    }

                    var i = 0;
                    var addTemplateDiv = function () {
                        var html = getTemplateHtml(i++);
                        $("#btnAddDiv2").prev().after(html);
                        form.render();
                        form.render('select');
                        $(".delBtn").off('click').on('click', function () {
                            var btn = $(this);
                            var btnId = btn[0].id;
                            var btnNo = btnId.substring("btnDel".length, btnId.length);
                            btn.parent().parent().parent().remove();
                        });
                    };

                    $('#btnAdd2').click(addTemplateDiv);
                    if (data && (data.eventType == 'addAttr' || data.eventType == 'addAttrFromAttrTable')) {
                        $("#btnAdd2").hide();
                    }
                    form.on('select(style)', function (data) {
                        if (data.value == 'text') {
                            $("#btnAdd2").hide();
                            $(".attributeDiv").remove();
                        } else if (data.value == 'single') {
                            $("#btnAdd2").show();
                            if ($("form input[name='value']").length == 0) {
                                addTemplateDiv();
                                $("#btnDel0").hide();
                            }
                        }
                    })
                    if (data && data.eventType == 'editAttr') {
                        if (data.style == 'single') {
                            $("#btnAdd2").show();
                        } else {
                            $("#btnAdd2").hide();
                        }
                    }

                    /*if(data==undefined||(data&&(data.eventType=='addAttr'||data.eventType=='addAttrFromAttrTable'))){
                        addTemplateDiv();
                        $("#btnDel0").hide();
                    }*/


                    if (data && data.eventType == 'editAttr') {
                        admin.req('enterprise/product/admin/productAttributeValue/list', {
                            productAttributeId: data.id,
                            limit: 9999
                        }, function (res) {
                            if (res.code == 200) {
                                for (var k = 0; k < res.data.length; k++) {
                                    addTemplateDiv();
                                    $("#btnDel0").hide();
                                    var elementNo = i - 1;
                                    var value = res.data[k].value;
                                    $("#value" + elementNo).val(value);
                                    form.render();
                                }

                            } else {
                                layer.msg('获取属性值失败', {icon: 2, time: 1000});
                            }
                        }, 'GET');
                    }

                    // 表单提交事件
                    form.on('submit(productAttrFormSubmit)', function (d) {
                        layer.load(2);
                        var detailList = [];
                        var vals = [];
                        var sorts = [];
                        $("form input[name='value']").each(function (index, item) {
                            var val = $(this).val();
                            vals.push(val);
                        });
                        if (d.field.style == 'single' && vals.length == 0) {
                            layer.msg('请添加固定值选择项', {icon: 2});
                            layer.closeAll('loading');
                            return false;
                        }


                        for (var k = 0; k < vals.length; k++) {
                            var obj = {value: vals[k]};
                            detailList.push(obj)
                        }
                        if (data && (data.eventType == 'addAttr' || data.eventType == 'addAttrFromAttrTable')) {
                            d.field.id = undefined;
                            d.field.productType = data.id;
                        } else {
                            d.field.productType = data.productType;
                        }
                        d.field.name = d.field.attrName;
                        d.field.detailList = detailList;
                        var isDeleted = $("form input[name='isDeleted']").prop("checked");
                        if (!isDeleted) {
                            d.field.isDeleted = false;
                        } else {
                            d.field.isDeleted = true;
                        }
                        admin.req(data && (data.eventType == 'addAttr' || data.eventType == 'addAttrFromAttrTable') ? 'enterprise/product/admin/productAttribute/add' : 'enterprise/product/admin/productAttribute/update', JSON.stringify(d.field), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                if (data && (data.eventType == 'addAttrFromAttrTable' || data.eventType == 'editAttr')) {
                                    table.reload('productAttrTable');
                                    layer.close(openIndex);
                                } else {
                                    layer.closeAll('page');
                                }

                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST', true, 'application/json; charset=utf-8');
                        return false;
                    });
                }
            });
        }


        //attr table
        function showAttrTableModel(data) {
            admin.open({
                type: 1,
                area: '1440px',
                offset: '65px',
                title: '物料属性管理',
                content: $('#attrTable').html(),
                success: function () {
                    // 渲染表格
                    var insTb = table.render({
                        elem: '#productAttrTable',
                        url: config.base + 'enterprise/product/admin/productAttribute/list?productType=' + data.id,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            , {type: 'numbers', title: '序号'}
                            , {field: 'name', align: 'center', title: '属性名称'}
                            , {field: 'attrHeader', align: 'center', title: '属性头'}
                            , {field: 'categoryName', align: 'center', title: '属性分类'}
                            , {field: 'productTypeName', align: 'center', title: '物料类别'}
                            , {
                                field: 'style', align: 'center', title: '属性类别', templet: function (d) {
                                    if (d.style == 'text') {
                                        return '文本';
                                    } else if (d.style == 'single') {
                                        return '单选';
                                    }
                                }
                            }
                            , {field: 'attrValues', align: 'center', title: '属性值'}
                            , {field: 'sortNumber', align: 'center', title: '排序'}
                            , {
                                field: 'isDeleted', align: 'center', title: '是否启用', templet: function (d) {
                                    if (d.isDeleted) {
                                        return '<input name="isDeleted" type="checkbox" lay-skin="switch" value="' + d.id + '" checked="' + d.isDeleted + '" lay-filter="isDeleted"  lay-text="启用|停用"/>';
                                    } else {
                                        return '<input name="isDeleted" type="checkbox" lay-skin="switch" value="' + d.id + '" lay-filter="isDeleted"   lay-text="启用|停用"/>';
                                    }

                                }
                            }
                            , {field: 'createTime', align: 'center', title: '创建时间'}
                            , {align: 'center', toolbar: '#productAttrTableBar', title: '操作', width: 200}
                        ]],
                        done: function (res, curr, count) {
                            //移除按钮
                            var menuButton = config.getMenuButton(location.hash);
                            if (menuButton.indexOf("搜索") == -1) {
                                $('.layui-form.toolbar').remove();
                            }
                            if (menuButton.indexOf("修改") == -1) {
                                $("[lay-event='edit']").remove();
                            }
                            if (menuButton.indexOf("删除") == -1) {
                                $("[lay-event='del']").remove();
                            }
                        }
                    });

                    // 工具条点击事件
                    table.on('tool(productAttrTable)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'editAttr') { //修改
                            data.eventType = 'editAttr'
                            showEditAttrModel(data);
                        } else if (obj.event === 'del') { // 删除
                            doDelete(obj);
                        }
                    });

                    function doDelete(obj) {
                        layer.confirm('确定要删除吗？', {
                            offset: '65px',
                            skin: 'layui-layer-admin'
                        }, function (i) {
                            layer.close(i);
                            layer.load(2);
                            admin.req('enterprise/product/admin/productAttribute/' + obj.data.id, {}, function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    obj.del();
                                    table.reload('productAttrTable');
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'DELETE');
                        });
                    }

                    //监听排序
                    table.on('sort(productAttrTable)', function (obj) {
                        table.reload('productAttrTable', {
                            initSort: obj
                            , where: {
                                sort: obj.field
                                , order: obj.type
                            }
                        });
                    });

                    // 搜索
                    form.on('submit(attrTableFormSubSearchLog)', function (data) {
                        insTb.reload({where: data.field, page: {curr: 1}}, 'data');
                    });

                    form.on('switch(isDeleted)', function (obj) {
                        if (obj.elem.checked) {
                            enable(obj.value)
                        } else {
                            disable(obj.value)
                        }
                    })

                    function enable(id) {
                        admin.req('enterprise/product/admin/productAttribute/enable', {id: id}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productAttrTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                    }

                    function disable(id) {
                        admin.req('enterprise/product/admin/productAttribute/disable', {id: id}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productAttrTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                    }

                    // 添加按钮点击事件
                    $('#productAttrBtnAdd').click(function () {
                        data.eventType = 'addAttrFromAttrTable'
                        showEditAttrModel(data);
                    });

                    $('#productAttrCategoryBtnAdd').click(function () {
                        data.eventType = 'addAttrFromAttrTable'
                        showEditAttrCategoryModel(data, undefined, 'productAttributeCategoryForm', 'productAttributeCategoryFormSubmit');
                    });

                    $('#productAttrBtnDel').click(function () {
                        var checkRows = table.checkStatus('productAttrTable');
                        if (checkRows.data.length == 0) {
                            layer.msg('请选择要删除的数据', {icon: 2});
                        } else {
                            var ids = '';
                            checkRows.data.forEach(item => {
                                ids += item.id + ','
                            })
                            delBatch(ids)
                        }
                    });

                    function delBatch(ids) {
                        admin.req('enterprise/product/admin/productAttribute/delBatch', {ids: ids}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productAttrTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST');
                    }
                }
            })
        }

        function showItemTableModel(data) {
            admin.open({
                type: 1,
                area: '1440px',
                offset: '65px',
                title: '检测项管理',
                content: $('#itemTable').html(),
                success: function () {
                    // 渲染表格
                    var insTb = table.render({
                        elem: '#productItemTable',
                        url: config.base + 'enterprise/product/admin/productItem/list?productType=' + data.id,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'},
                            {field: 'name', align: 'center', title: '检测项目名称'},
                            {field: 'code', align: 'center', title: '检测项目编码'},
                            {field: 'itemCategoryName', align: 'center', title: '所属检测项目分类'},
                            {field: 'itemTypeName', align: 'center', title: '检测类型'},
                            {field: 'productTypeName', align: 'center', title: '所属物资分类'},
                            {field: 'productNatureName', align: 'center', title: '物资性质'},
                            {field: 'createTime', align: 'center', title: '创建时间'},
                            {align: 'center', toolbar: '#productItemTableBar', title: '操作', width: 200}
                        ]],
                        done: function (res, curr, count) {
                            //移除按钮
                            var menuButton = config.getMenuButton(location.hash);
                            if (menuButton.indexOf("搜索") == -1) {
                                $('.layui-form.toolbar').remove();
                            }
                            if (menuButton.indexOf("修改") == -1) {
                                $("[lay-event='edit']").remove();
                            }
                            if (menuButton.indexOf("删除") == -1) {
                                $("[lay-event='del']").remove();
                            }
                        }
                    });

                    // 工具条点击事件
                    table.on('tool(productItemTable)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'editItem') { //修改
                            data.eventType = 'editItem'
                            showEditItemModel(data);
                        } else if (obj.event === 'del') { // 删除
                            doDelete(obj);
                        }
                    });

                    function doDelete(obj) {
                        layer.confirm('确定要删除吗？', {
                            offset: '65px',
                            skin: 'layui-layer-admin'
                        }, function (i) {
                            layer.close(i);
                            layer.load(2);
                            admin.req('enterprise/product/admin/productItem/' + obj.data.id, {}, function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    obj.del();
                                    table.reload('productItemTable');
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'DELETE');
                        });
                    }

                    //监听排序
                    table.on('sort(productItemTable)', function (obj) {
                        table.reload('productItemTable', {
                            initSort: obj
                            , where: {
                                sort: obj.field
                                , order: obj.type
                            }
                        });
                    });

                    // 搜索
                    form.on('submit(itemTableFormSubSearchLog)', function (data) {
                        insTb.reload({where: data.field, page: {curr: 1}}, 'data');
                    });

                    form.on('switch(isDeleted)', function (obj) {
                        if (obj.elem.checked) {
                            enable(obj.value)
                        } else {
                            disable(obj.value)
                        }
                    })

                    function enable(id) {
                        admin.req('enterprise/product/admin/productAttribute/enable', {id: id}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productAttrTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                    }

                    function disable(id) {
                        admin.req('enterprise/product/admin/productAttribute/disable', {id: id}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productAttrTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                    }

                    // 添加按钮点击事件
                    $('#productItemBtnAdd').click(function () {
                        data.eventType = 'addItemFromAttrTable'
                        showEditItemModel(data);
                    });

                    $('#productItemCategoryBtnAdd').click(function () {
                        data.eventType = 'addItemFromAttrTable'
                        showEditItemCategoryModel(data, undefined, 'productItemCategoryForm', 'productItemCategoryFormSubmit');
                    });

                    $('#productAttrBtnDel').click(function () {
                        var checkRows = table.checkStatus('productAttrTable');
                        if (checkRows.data.length == 0) {
                            layer.msg('请选择要删除的数据', {icon: 2});
                        } else {
                            var ids = '';
                            checkRows.data.forEach(item => {
                                ids += item.id + ','
                            })
                            delBatch(ids)
                        }
                    });

                    function delBatch(ids) {
                        admin.req('enterprise/product/admin/productAttribute/delBatch', {ids: ids}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productAttrTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST');
                    }
                }
            })
        }

        function showEditItemModel(data) {
            var openIndex = admin.open({
                type: 1,
                area: '740px',
                offset: '65px',
                title: data && (data.eventType == 'addItem' || data.eventType == 'addItemFromAttrTable') ? '添加物资检测项目' : '修改物资检测项目',
                content: $('#productItemForm').html(),
                success: function () {
                    //初始化物资分类
                    admin.initDataSelect('enterprise/product/admin/productType/list', {limit: 9999}, 'productType', data.productType != null ? data.productType : data.id, '物资分类', null, null);
                    //初始化物资性质
                    admin.getDictList("productNature", "sys_product_type_nature", data.productNature != null ? data.productNature : data.materialNature, "物资性质");
                    //初始化检测类型
                    admin.getDictList("itemType", "sys_product_item_type", data.itemType, "检测类型");
                    //初始化检测项目分类
                    admin.initDataSelect('enterprise/product/admin/productItemCategory/list', {limit: 9999}, 'itemCategoryId', data.itemCategoryId, '检测项目分类', null, null);
                    //初始化样式
                    admin.getDictList("style", "sys_product_item_style", data.style, "检测样式");

                    if (data && data.eventType != 'addItem' && data.eventType != 'addItemFromAttrTable') {
                        form.val('productItemForm', data);
                    }

                    var getTemplateHtml = function (i) {
                        var labelName = '';
                        var valLen = $("form input[name='value']").length;
                        var classNew = '';
                        if (valLen == 0) {
                            labelName = '属性值';
                        } else {
                            classNew = 'newAdd'
                        }
                        var templateHtml = '' +
                            '<div class="attributeDiv layui-form-item ' + classNew + '" >' +
                            '<div class="layui-form-item">' +
                            '<div >' +
                            '<label class="layui-form-label" >' + labelName + '</label>' +
                            '<div class="layui-input-inline">' +
                            '<input id="value' + i + '" name="value" placeholder="请输入属性" type="text" class="layui-input" lay-verify="required" required/>' +
                            '</div>' +
                            '</div>' +
                            '<div >' +
                            '</div>';
                        templateHtml += '<div class="layui-input-inline">' +
                            '<button id="btnDel' + i + '" class="layui-btn delBtn" lay-filter="btnDel' + i + '" style="margin-left: 20px;">删除</button>' +
                            '</div>';
                        templateHtml += '</div>' + '</div>';
                        return templateHtml;
                    }

                    var addTemplateDiv = function () {
                        var html = getTemplateHtml(i++);
                        $("#btnAddDiv2").prev().after(html);
                        form.render();
                        form.render('select');
                        $(".delBtn").off('click').on('click', function () {
                            var btn = $(this);
                            var btnId = btn[0].id;
                            var btnNo = btnId.substring("btnDel".length, btnId.length);
                            btn.parent().parent().parent().remove();
                        });
                    };

                    $('#btnAdd').click(addTemplateDiv);
                    if (data && (data.eventType == 'addItem' || data.eventType == 'addItemFromAttrTable')) {
                        $("#btnAdd").hide();
                    }

                    form.on('select(style)', function (data) {
                        if (data.value == 'text') {
                            $("#btnAdd").hide();
                            $(".attributeDiv").remove();
                        } else if (data.value == 'single') {
                            $("#btnAdd").show();
                            if ($("form input[name='value']").length == 0) {
                                addTemplateDiv();
                                $("#btnDel0").hide();
                            }
                        }
                    })

                    // 表单提交事件
                    form.on('submit(productItemFormSubmit)', function (d) {
                        layer.load(2);
                        var isDeleted = $("form input[name='isDeleted']").prop("checked");
                        if (!isDeleted) {
                            d.field.isDeleted = false;
                        } else {
                            d.field.isDeleted = true;
                        }
                        admin.req(data && (data.eventType == 'addItem' || data.eventType == 'addItemFromAttrTable') ? 'enterprise/product/admin/productItem/add' : 'enterprise/product/admin/productItem/update', JSON.stringify(d.field), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                if (data && (data.eventType == 'addItemFromAttrTable' || data.eventType == 'editItem')) {
                                    table.reload('productItemTable');
                                    layer.close(openIndex);
                                } else {
                                    layer.closeAll('page');
                                }

                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST', true, 'application/json; charset=utf-8');
                        return false;
                    });
                }
            });
        }

        function showEditItemCategoryModel(productTypeData, data, formId, submitButton, parentIdVal) {
            var openIndex = admin.open({
                type: 1,
                area: '440px',
                offset: '65px',
                title: '添加检测项目分类',
                content: $('#productItemCategoryForm').html(),
                success: function () {
                    //初始化物资分类
                    admin.initDataSelectTree(true, 'enterprise/product/admin/productType/getTreeData', {limit: 9999}, 'selectProductTypeQuery', productTypeData.id, '物资分类', 'productType', null);
                    //初始化物资性质
                    admin.getDictList("productNature", "sys_product_type_nature", productTypeData.materialNature, "物资性质");
                    //初始化检测类型
                    admin.getDictList("itemType", "sys_product_item_type", null, "检测类型");

                    // 表单提交事件
                    form.on('submit(' + submitButton + ')', function (d) {
                        layer.load(2);
                        var isDeleted = $("form input[name='isDeleted']").prop("checked");
                        if (!isDeleted) {
                            d.field.isDeleted = false;
                        } else {
                            d.field.isDeleted = true;
                        }
                        d.field.productType = productTypeData.id;
                        admin.req(data ? 'enterprise/product/admin/productItemCategory/update' : 'enterprise/product/admin/productItemCategory/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                layer.close(openIndex)
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }
            })
        }

        //工序设置
        function showProcessModel(data) {
            admin.open({
                type: 1,
                area: '1600px',
                offset: '65px',
                title: '工序设置',
                content: $('#processInfoWindow').html(),
                success: function () {
                    // 渲染表格
                    var insTb = table.render({
                        elem: '#processInfoTable',
                        url: config.base + 'enterprise/product/admin/processInfo/list?productTypeId=' + data.id,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            , {type: 'numbers', title: '序号'}
                            , {field: 'nodeNames', align: 'center', title: '工段节点名称'}
                            , {field: 'nodeNames', align: 'center', title: '适用责任生产车间'}
                            , {field: 'nodeCodes', align: 'center', title: '工段节点编号'}
                            , {field: 'remark', align: 'center', title: '备注说明'}

                            , {
                                field: 'nodeTypes', align: 'center', title: '节点类别', templet: function (d) {
                                    if (d.nodeTypes == '1') {
                                        return '流水线节点（线排配）';
                                    } else if (d.nodeTypes == '2') {
                                        return '机加工节点（站排配）';
                                    } else if (d.nodeTypes == '3') {
                                        return '单一离散节点（站排配）';
                                    }
                                }
                            }
                            , {
                                field: 'isDetectionAll', align: 'center', title: '抽检', templet: function (d) {
                                    if (d.isDetectionAll == '0') {
                                        return '是';
                                    } else if (d.isDetectionAll == '1') {
                                        return '否';
                                    }
                                }
                            }
                            , {
                                field: 'isOutsource', align: 'center', title: '是否支持委外', templet: function (d) {
                                    if (d.isOutsource == '0') {
                                        return '不支持';
                                    } else if (d.isOutsource == '1') {
                                        return '支持';
                                    }
                                }
                            }
                            , {field: 'createTime', align: 'center', title: '创建时间'}
                        ]],
                        done: function (res, curr, count) {

                        }
                    });
                    $('#processInfoBtnAdd').click(function () {
                        showProcessInfoAddEditModel(data);
                    });

                    function showProcessInfoAddEditModel(data) {
                        admin.open({
                            type: 1,
                            area: '1600px',
                            offset: '65px',
                            title: '添加工序',
                            content: $('#processInfoAddWindow').html(),
                            success: function () {
                                var insTb = table.render({
                                    elem: '#processInfoAddTable',
                                    url: config.base + 'enterprise/product/admin/processInfo/list?productTypeId=' + data.id + '&type=1',
                                    page: true,
                                    cellMinWidth: 100,
                                    cols: [[
                                        {type: 'checkbox'}
                                        , {type: 'numbers', title: '序号'}
                                        , {field: 'nodeNames', align: 'center', title: '工段节点名称'}
                                        , {field: 'nodeNames', align: 'center', title: '适用责任生产车间'}
                                        , {field: 'nodeCodes', align: 'center', title: '工段节点编号'}
                                        , {field: 'remark', align: 'center', title: '备注说明'}

                                        , {
                                            field: 'nodeTypes',
                                            align: 'center',
                                            title: '节点类别',
                                            templet: function (d) {
                                                if (d.nodeTypes == '1') {
                                                    return '流水线节点（线排配）';
                                                } else if (d.nodeTypes == '2') {
                                                    return '机加工节点（站排配）';
                                                } else if (d.nodeTypes == '3') {
                                                    return '单一离散节点（站排配）';
                                                }
                                            }
                                        }
                                        , {
                                            field: 'isDetectionAll',
                                            align: 'center',
                                            title: '抽检',
                                            templet: function (d) {
                                                if (d.isDetectionAll == '0') {
                                                    return '是';
                                                } else if (d.isDetectionAll == '1') {
                                                    return '否';
                                                }
                                            }
                                        }
                                        , {
                                            field: 'isOutsource',
                                            align: 'center',
                                            title: '是否支持委外',
                                            templet: function (d) {
                                                if (d.isOutsource == '0') {
                                                    return '不支持';
                                                } else if (d.isOutsource == '1') {
                                                    return '支持';
                                                }
                                            }
                                        }
                                        , {field: 'createTime', align: 'center', title: '创建时间'}
                                    ]],
                                    done: function (res, curr, count) {
                                        // 设置背景颜色
                                        let backgroundColor = "#eaeaea";
                                        let table_data = res.data;
                                        for (let i = 0; i < table_data.length; i++) {
                                            let elect = table_data[i].elect;
                                            if (!elect) {
                                                console.log(table_data[i])
                                                $('th[data-field="0"] input[type="checkbox"]').prop('disabled', true); // 禁止全选
                                                $(".layui-table tr[data-index=" + i + "] input[type='checkbox']").prop('disabled', true); //禁止部分选择
                                                $(".layui-table tr[data-index=" + i + "] input[type='checkbox']").next().addClass('layui-btn-disabled');
                                                $('div[lay-id="processInfoAddTable"]').find('tr[data-index =' + i + ']').css("background-color", backgroundColor);
                                            }
                                        }
                                    }
                                });

                                form.on('submit(processInfoAddSubmit)', function (d) {
                                    var para = {};
                                    var check = table.checkStatus('processInfoAddTable');
                                    var ids = [];
                                    $(check.data).each(function (i, o) {// o 即为表格中一行的数据
                                        ids.push(o.id);
                                    });
                                    para["processIds"] = ids;
                                    para["productTypeId"] = data.id;
                                    console.log(para)
                                    admin.req('enterprise/product/admin/productTypeProcess/add', para, function (res) {
                                        if (res.code == 200) {
                                            layer.msg(res.msg, {icon: 1});
                                            table.reload('productAttrTable');

                                        } else {
                                            layer.msg(res.msg, {icon: 2});
                                        }
                                        layer.closeAll('page');
                                    }, 'POST');
                                })
                            }
                        })
                    }
                }
            })
        }

        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprise/product/admin/productType/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        // 模板下载
        $('#productTypeBtnTemplate').click(function () {
            window.location.href = config.base + "enterprise/product/admin/productType/template";
        });

        //导入excel
        $('#uploaderInput').on("change", function (e) {
            layer.load(2);
            var formData = new FormData();
            var files = e.target.files;
            let that = $(this);
            formData.append("file", files[0]);
            formData.append("name", files[0].name);//这个地方可以传递多个参数
            $.ajax({
                url: config.base + 'enterprise/product/admin/productType/importExcel',
                data: formData,
                headers: {Authorization: 'Bearer ' + config.getToken()},
                type: "POST",
                processData: false,
                contentType: false,
                success: function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        layer.closeAll('page');
                        setTimeout(_ => {
                            location.reload()
                        }, 1000);
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                    that.val('');
                }
            });
        })

        // 导出excel
        $('#productTypeBtnExport').click(function () {
            var checkRows = table.checkStatus('productTypeTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });

    });
</script>